package com.tencent.qf.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.base.Strings;
import com.tencent.qf.user.dal.UserCoreInfo;
import com.tencent.qf.user.dal.entity.DepartmentDO;
import com.tencent.qf.user.dal.mapper.DepartmentMapper;
import com.tencent.qf.user.dao.UserCoreInfoMapper;
import com.tencent.qf.user.service.UserCoreInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
* @author p_haojiawu
* @description 针对表【t_user_core_info(账户核心信息)】的数据库操作Service实现
* @createDate 2023-05-23 15:15:05
*/
@Service
public class UserCoreInfoServiceImpl implements UserCoreInfoService {

    @Resource
    private UserCoreInfoMapper userCoreInfoMapper;

    @Resource
    private DepartmentMapper departmentMapper;

    public DepartmentDO getAreaInfoByUid(String uid){
        DepartmentDO result = new DepartmentDO();
        QueryWrapper<UserCoreInfo> userCoreInfoQuery = new QueryWrapper<>();
        userCoreInfoQuery.select("str_slot7")
                .eq("uid", uid)
                .eq("status", 0);
        List<Map<String, Object>> maps = userCoreInfoMapper.selectMaps(userCoreInfoQuery);
        // 用户存在
        if(maps.size() > 0){
            String strSlot7 = (String)maps.get(0).get("str_slot7");
            // 有插槽属性 ｜｜ 有区域id
            if(!Strings.isNullOrEmpty(strSlot7) && strSlot7.split(",").length >= 2){
                String deptId = strSlot7.split(",")[1];
                QueryWrapper<DepartmentDO> departmentQuery = new QueryWrapper<>();
                departmentQuery.eq("dept_id", deptId)
                        .eq("is_deleted", 0);
                result = departmentMapper.selectList(departmentQuery).get(0);
            }
        }
        return result;
    }
}




